package engine.ui 
{
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.control.window.NxWindowEvent;
	
	/**
	 * ...
	 * @author ...gyq
	 */
	public class SPSwapUI extends BaseUI 
	{
		private static var _self:SPSwapUI;
		private static var _model			:ModelLocator;
		private static  const NO_ENOUTH_GOLD:int = 2; //金币不足
		public static  const GET_NEW_EQUIP:int = 0;	//获得新装备
		private static  const DEAD_IN_FB:int = 1;		//副本中死亡
		public var btn_ok:NxButton;
		public var txt_info:NxText;
		public var checkbox:MovieClip;
		public var lab_notice:NxLabel;
		public var _isopen:int = 1;
		public function SPSwapUI() 
		{
			
		}
		
		public static function getInstance():SPSwapUI
		{
			if(_self == null)
			{
				_self = new SPSwapUI();
			}
			return _self;
		}
		
		override public function Init():void
		{
			checkbox.buttonMode = true;
			lab_notice.buttonMode = true;
			_model = ModelLocator.getInstance();
			//_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_BUY_MAGICCOIN), onShow);
		}
		
		
		private function oncheckboxHandle(e:MouseEvent):void
		{
			if (_isopen == 1)
			{
				checkbox.gotoAndStop(2);
				_isopen = 2;
			}else
			if (_isopen == 2)
			{
				checkbox.gotoAndStop(1);
				_isopen = 1;
			}
		}
		public function onShow(Str:String,e:CustomMsgEvent=null):void
		{
			if (_isopen == 1)
			{
				//txt_info.htmlStr = StaticIni.getSwfLangStrVar("UIStr_1001769", [e.pList[1], e.pList[0]]);
				txt_info.htmlStr  = Str;
				show();
			}else {
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_BUY_SP);
			}
		}
		private function onClickClose(e:NxWindowEvent):void
		{
			hide();
		}
		
		private function onGoldHandle(e:MouseEvent):void
		{
			MagicChangeToGoldUI.getInstance().showByType();
		}
		
		private function onActivityHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_BUY_SP);
			hide();
		}
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			checkbox.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.addEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			btn_ok.addEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		
		/**
		 *移除监听 
		 * 
		 */
		private function removeListenter():void
		{
			checkbox.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			lab_notice.removeEventListener(MouseEvent.CLICK, oncheckboxHandle);
			windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE, onClickClose);
			btn_ok.removeEventListener(MouseEvent.CLICK,onActivityHandle);
		}
		
		override protected function BeforeShow():void
		{
			checkbox.gotoAndStop(_isopen);
			addListenter();
		}
		
		override protected function AfterHide():void
		{
			removeListenter();
		}
		
	}

}